import com.demo.component.BeanLifeComponent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

// 配合 BeanLifeComponent 类 演示 Bean 的生命周期.
public class AppBeanLife {
    public static void main(String[] args) {

        // ClassPathXmlApplicationContext 是 ApplicationContext 的子类, 里面有销毁方法, 易于观察.
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");
        BeanLifeComponent lifeComponent =
                context.getBean("myComponent", BeanLifeComponent.class);
        System.out.println("使用 Bean");

        // 销毁 Bean
        context.destroy();

    }
}
